package me.kennylee.mobile.sms.code.validator;

import me.kennylee.mobile.sms.cache.EhcacheValidator;
import me.kennylee.mobile.sms.cache.SmsCodeCacheKey;
import me.kennylee.mobile.sms.code.SmsResponse;

/**
 * <p> 短信发送次数验证 </p>
 * <p>Created on 6/2/2018.</p>
 *
 * @author kennylee
 */
public class SmsCountValidator extends EhcacheValidator implements SendCodeValidator {

    private static int MOBILE_MAX_SMS = 10;

    @Override
    public SmsResponse check(String mobile) {
        Integer times = get(mobile);
        return times == null || times < getMobileMaxSms() ? SmsResponse.success() :
                SmsResponse.error(this.getCacheName());
    }

    @Override
    protected String getCacheName() {
        return SmsCodeCacheKey.getMobileSmsCount();
    }

    public static int getMobileMaxSms() {
        return MOBILE_MAX_SMS;
    }

    public static void setMobileMaxSms(int mobileMaxSms) {
        MOBILE_MAX_SMS = mobileMaxSms;
    }
}